//
//  ReportVC.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/22.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
import SVProgressHUD
class ReportVC: UIViewController {
    @IBOutlet weak var btn1: UIButton!//按钮是从上到下进行排序的
    @IBOutlet weak var btn2: UIButton!
    @IBOutlet weak var btn3: UIButton!
    @IBOutlet weak var btn4: UIButton!
    @IBOutlet weak var btn5: UIButton!
    @IBOutlet weak var btn6: UIButton!
    
    @IBOutlet weak var complet: UIButton!
    var msg: regiestInfo?
    var reportContentArr: [String] = []
    var id: String!
    override func viewDidLoad() {
        super.viewDidLoad()
        publicMethod.setHUDStyle()
        self.complet.layer.masksToBounds = true
        self.complet.layer.cornerRadius = 20

        
    }
    override func viewWillDisappear(animated: Bool) {
        SVProgressHUD.dismiss()
        super.viewWillDisappear(animated)
    }
    @IBAction func btnClicked(sender: UIButton){
        
        if sender == self.btn1{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("内容重复")
                self.btn1.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                self.btn1.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("内容重复")!)
            }
            
        }
        if sender == self.btn2{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("有错别字")
                self.btn2.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                 self.btn2.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("有错别字")!)
            }
            
        }
        if sender == self.btn3{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("排版有误")
                self.btn3.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                self.btn3.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("排版有误")!)
            }
            
        }
        if sender == self.btn4{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("观点错误")
                self.btn4.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                self.btn4.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("观点错误")!)
            }
            
        }
        if sender == self.btn5{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("与事实不符")
                self.btn5.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                self.btn5.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("与事实不符")!)
            }
            
        }
        if sender == self.btn6{
            sender.selected = !sender.selected
            if sender.selected{
                reportContentArr.append("品牌侵权")
                self.btn6.setImage(UIImage(named: "fangkuang_selected"), forState: UIControlState.Normal)
            }else{
                self.btn6.setImage(UIImage(named: "fangkuang"), forState: UIControlState.Normal)
                reportContentArr.removeAtIndex(reportContentArr.indexOf("品牌侵权")!)
            }
            
        }
        
    }
    //提交按钮的点击事件
    @IBAction func completBtnClicked(sender: UIButton){
        if self.reportContentArr.count == 0{
           SVProgressHUD.showErrorWithStatus("请选择举报原因")
           return
        }else{
            self.submitReportContent()
        }
        
    }
    
    //MARK:NETWORKING
    func submitReportContent(){
        DataTool.report(reportContentArr, id: self.id!, completionHandler: { (newModel) in
            guard newModel != nil else {
                return
            }
            self.msg = newModel
            
            SVProgressHUD.showSuccessWithStatus(self.msg?.msg)
            
        })

    }

    
}
